
/****************************************************************************/
/*Copyright (c) 2011, Florent DEVILLE.                                      */
/*All rights reserved.                                                      */
/*                                                                          */
/*Redistribution and use in source and binary forms, with or without        */
/*modification, are permitted provided that the following conditions        */
/*are met:                                                                  */
/*                                                                          */
/* - Redistributions of source code must retain the above copyright         */
/*notice, this list of conditions and the following disclaimer.             */
/* - Redistributions in binary form must reproduce the above                */
/*copyright notice, this list of conditions and the following               */
/*disclaimer in the documentation and/or other materials provided           */
/*with the distribution.                                                    */
/* - The names of its contributors cannot be used to endorse or promote     */
/*products derived from this software without specific prior written        */
/*permission.                                                               */
/* - The source code cannot be used for commercial purposes without         */ 
/*its contributors' permission.                                             */
/*                                                                          */
/*THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS       */
/*"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT         */
/*LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS         */
/*FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE            */
/*COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,       */
/*INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,      */
/*BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;          */
/*LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER          */
/*CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT        */
/*LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN         */
/*ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE           */
/*POSSIBILITY OF SUCH DAMAGE.                                               */
/****************************************************************************/

#pragma once

#include "RTVector3f.h"

//macro to access directly a specific component
#define RTVEC4X _xyzw[0]
#define RTVEC4Y _xyzw[1]
#define RTVEC4Z _xyzw[2]
#define RTVEC4W _xyzw[3]

namespace RT
{

	//Vector composed of four components, X, Y, Z and W
	class RTVector4f
	{
	public :
		//the four components of the vector
		F32 _xyzw[4];
	
	public:
		//empty constructor, set all values to 0
		RTVector4f();

		//constructor from a Vector3f
		RTVector4f(const RTVector3f& v, F32 w);

		//constructor : set the values to the parameter's value
		RTVector4f(F32 x, F32 y, F32 z, F32 w);

		//destructor
		~RTVector4f();

		//add two vectors and return the result
		RTVector4f operator +(const RTVector4f& v)const;

		//substract two vectors and return the result
		RTVector4f operator -(const RTVector4f& v)const;

		//unary substract operation
		RTVector4f operator -()const;

		//multiply with a F32 and return the result
		RTVector4f operator *(F32 a)const;

		//multiply two vectors and return the result
		RTVector4f operator *(const RTVector4f& v)const;

		//multiply a vector by a matrix
		RTVector4f operator*(const RTMatrix44& m)const;

		//divide with a F32 and return the result
		RTVector4f operator /(F32 a)const;

		//add the parameter and store the result
		void operator += (const RTVector4f& v);

		//add the parameter and store the result
		void operator += (const RTVector3f& v);

		//multiply with the parameter and store the result
		void operator *= (F32 f);

		//equality test. Return true if the two vectors are equals. Return false if the vectors have different values.
		bool operator == (const RTVector4f& v);

		//Return true if the two vectors are different and false if there are equals
		bool operator != (const RTVector4f& v);

		//calculate a dot product (the fourth parameter is ignored)
		F32 dot(const RTVector4f& v)const;

		//calculate a cross product (the fourth parameter is ignored)
		RTVector4f cross(const RTVector4f& v)const;

		//calculate the vector's norme
		F32 norme()const;

		//calculate the vector's square norme
		F32 norme2()const;

		//normalize the vector
		void normalize();

		//saturate the vector between 0 and 1
		void saturate();

		//set the vector to the distance given as parameter
		void maximize(F32 max);

		//conversion operator to RTVector3f
		operator RTVector3f();
	};

}